package cn.qu.phizline.webserver.api.v1.controller;

import cn.qu.phizline.event.Payload;
import cn.qu.phizline.event.init.InitEvent;
import cn.qu.phizline.event.login.LoginEvent;
import cn.qu.phizline.webserver.api.v1.service.Apiv1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zh on 2017/9/18.
 */
@RestController
@RequestMapping("/api/1")
public class IndexController {

    @Autowired
    private Apiv1Service apiv1Service;

    /**
     * 登录 2
     * @param payload
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST,
            consumes = "application/x1-payload", produces = "application/x1-payload")
    public Payload login(@RequestBody LoginEvent payload) {
        return apiv1Service.process(payload);
    }

    /**
     * 初始化密钥 1
     * @param payload
     * @return
     */
    @RequestMapping(value = "/init", method = RequestMethod.POST,
            consumes = "application/x1-payload", produces = "application/x1-payload")
    public Payload init(@RequestBody InitEvent payload) {
        return apiv1Service.process(payload);
    }


}
